﻿using Common.Service;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using RabitPart.WritedPartApi.Application.Comman.TraceabilityFile;

namespace RabitPart.WritedPartApi.Controllers
{
    /// <summary>
    /// 溯源管理--控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class TraceabilityModuleController : ControllerBase
    {
        private readonly IMediator mediator;
        private readonly ILogger<TraceabilityModuleController> logger;

        public TraceabilityModuleController(IMediator mediator, ILogger<TraceabilityModuleController> logger)
        {
            this.mediator = mediator;
            this.logger = logger;
        }


        /// <summary>
        /// 添加--溯源管理
        /// </summary>
        /// <param name="model">实体</param>
        /// <returns>添加--溯源管理</returns>
        [HttpPost]
        public async Task<ApiResult> CreateCompany(TraceabilityCreateComman model)
        {
            try
            {
                return await mediator.Send(model);
            }
            catch (Exception ex)
            {
                logger.LogError("添加溯源信息异常" + ex.Message);
                throw;
            }
        }


        /// <summary>
        /// 删除--溯源管理
        /// </summary>
        /// <param name="model">实体</param>
        /// <returns>删除--溯源管理</returns>
        [HttpPost]
        public async Task<ApiResult> DelecteCompany(TraceabilityDelecteComman model)
        {
            try
            {
                return await mediator.Send(model);
            }
            catch (Exception ex)
            {
                logger.LogError("添加溯源信息异常" + ex.Message);
                throw;
            }
        }


        /// <summary>
        /// 更新--溯源管理
        /// </summary>
        /// <param name="model">实体</param>
        /// <returns>更新--溯源管理</returns>
        [HttpPost]
        public async Task<ApiResult> UPdateCompany(TraceabilityUpdateComman model)
        {
            try
            {
                return await mediator.Send(model);
            }
            catch (Exception ex)
            {
                logger.LogError("更新溯源信息异常" + ex.Message);
                throw;
            }
        }



    }
}
